﻿Imports MySql.Data.MySqlClient

Public Class PanelClasss
    Public costo As Integer
    Public asignacion As Integer
    Public verificacion As Integer
    Public espacioBodega As Integer
    Public produccionEmpresa As Integer
    Public fila As Integer
    Public columna As Integer
    Dim con As Conexion = New Conexion

    Public Sub guardarJuego(ByVal fila As String, ByVal columna As String, ByVal fecha As String, ByVal estado As Integer, ByVal costo As Integer, ByVal costoFinal As Integer, ByVal metodo As Integer, ByVal iteraciones As Integer)
        con.conectar()
        Dim sql2 As String = "INSERT INTO juegoprincipal(jue_id ,jue_fil,jue_col,jue_costoInicial,jue_costoFinal,jue_fecha,est_id, met_id,jue_iteraciones) VALUES (NULL, '" & fila & "','" & columna & "','" & costo & "','" & costoFinal & "','" & fecha & "','" & estado & "','" & metodo & "','" & iteraciones & "');"
        Dim comandoSQL1 As New MySqlCommand(sql2, con.conexion)
        comandoSQL1.ExecuteScalar()
        con.cerrar()
    End Sub

    Public Sub almacenarPaneles()
        'llamar  a la matriz que pertenece al formulario'
        con.conectar()
        Dim CantidadEmpresas As Integer = Integer.Parse(grupbox1.NumEmpresas.Text)
        Dim CantidadBodegas As Integer = Integer.Parse(grupbox1.NumBodegas.Text)
        For i = 1 To CantidadEmpresas
            For j = 1 To CantidadBodegas
                ''If grupbox1.matriz(i, j).asignacion <> 0 Then
                Dim sql2 As String = "INSERT INTO panel(pan_id ,jue_id,pan_costo,pan_asig,pan_ver,pan_fil,pan_col) VALUES (NULL,(SELECT MAX(jue_id) FROM juegoprincipal),'" & grupbox1.matriz(i, j).costo & "','" & grupbox1.matriz(i, j).asignacion & "','" & grupbox1.matriz(i, j).verificacion & "','" & i & "','" & j & "')"
                Dim comandoSQL1 As New MySqlCommand(sql2, con.conexion)
                comandoSQL1.ExecuteScalar()
                '' End If
            Next
        Next
        con.cerrar()
    End Sub
    Public Sub almacenarCapacidades()
        con.conectar()
        Dim sql As String
        Dim CantidadEmpresas As Integer = Integer.Parse(grupbox1.NumEmpresas.Text)
        Dim CantidadBodegas As Integer = Integer.Parse(grupbox1.NumBodegas.Text)
        For i = 1 To CantidadEmpresas
            For Each elemento As Control In grupbox1.splitContainer1.Panel1.Controls
                If TypeOf elemento Is NumericUpDown Then
                    If elemento.Name = "NumericUpDown" & i & 1 Then
                        sql = "INSERT INTO fabricas(fab_id ,jue_id,fab_pos,fab_val) VALUES (NULL,(SELECT MAX(jue_id) FROM juegoprincipal),'" & i & "','" & elemento.Text & "')"
                        Dim comandoSQL1 As New MySqlCommand(sql, con.conexion)
                        comandoSQL1.ExecuteScalar()
                    End If
                End If
            Next
        Next
        For i = 1 To CantidadBodegas
            For Each elemento As Control In grupbox1.splitContainer1.Panel1.Controls
                If TypeOf elemento Is NumericUpDown Then
                    If elemento.Name = "NumericUpDow1" & i Then
                        sql = "INSERT INTO bodegas(bod_id ,jue_id,bod_pos,bod_val) VALUES (NULL,(SELECT MAX(jue_id) FROM juegoprincipal),'" & i & "','" & elemento.Text & "')"
                        Dim comandoSQL1 As New MySqlCommand(sql, con.conexion)
                        comandoSQL1.ExecuteScalar()
                    End If
                End If
            Next
        Next
        con.cerrar()
    End Sub

End Class
